<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>皮影快闪 - 启动中</title>
  <style>
    html, body {
      margin: 0;
      padding: 0;
      height: 100%;
      overflow: hidden;
      font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
      background-color: transparent;
      -webkit-app-region: drag; /* 允许拖动窗口 */
    }

    .splash-screen {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 9999;
      background-color: transparent;
    }

    .splash-content {
      width: 360px;
      text-align: center;
      background-color: rgba(255, 255, 255, 0.95);
      border-radius: 20px;
      padding: 30px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      animation: fadeIn 0.5s ease-out;
    }

    .logo-container {
      margin-bottom: 20px;
      position: relative;
    }

    .logo-bg {
      width: 120px;
      height: 120px;
      background-color: #fff;
      border-radius: 30px;
      margin: 0 auto;
      display: flex;
      justify-content: center;
      align-items: center;
      box-shadow: 0 10px 20px rgba(255, 125, 0, 0.15);
    }

    .app-logo {
      width: 90px;
      height: 90px;
      object-fit: contain;
      animation: pulse 2s infinite;
    }

    .app-name {
      font-size: 24px;
      font-weight: 600;
      margin: 0 0 24px 0;
      color: #333;
      background: linear-gradient(45deg, #ff7d00, #ff9500);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      letter-spacing: 1px;
    }

    .loading-container {
      margin-bottom: 20px;
    }

    .progress-bar {
      height: 6px;
      background-color: rgba(0, 0, 0, 0.05);
      border-radius: 10px;
      overflow: hidden;
      position: relative;
      margin: 0 10px;
    }

    .progress-value {
      height: 100%;
      background: linear-gradient(90deg, #ff7d00, #ff9500);
      border-radius: 10px;
      width: 0%;
      transition: width 0.3s ease;
      box-shadow: 0 0 10px rgba(255, 125, 0, 0.5);
    }

    .loading-text {
      margin-top: 12px;
      font-size: 14px;
      color: #666;
    }

    .version-info {
      font-size: 12px;
      color: #999;
      margin: 0;
    }

    .debug-info {
      margin-top: 10px;
      font-size: 10px;
      color: #999;
      opacity: 0.7;
    }

    @keyframes pulse {
      0% {
        transform: scale(1);
      }
      50% {
        transform: scale(1.05);
      }
      100% {
        transform: scale(1);
      }
    }

    @keyframes fadeIn {
      from {
        opacity: 0;
        transform: translateY(20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    .dots {
      display: inline-block;
      position: relative;
      width: 10px;
      text-align: left;
    }

    .dots::after {
      content: '';
      animation: dots 1.5s infinite;
    }

    @keyframes dots {
      0% { content: ''; }
      25% { content: '.'; }
      50% { content: '..'; }
      75% { content: '...'; }
      100% { content: ''; }
    }
  </style>
</head>
<body>
  <div class="splash-screen">
    <div class="splash-content">
      <div class="logo-container">
        <div class="logo-bg">
          <img src="./src/assets/logo.svg" alt="皮影快闪" class="app-logo" id="app-logo">
        </div>
      </div>
      <h1 class="app-name">皮影快闪</h1>
      <div class="loading-container">
        <div class="progress-bar">
          <div class="progress-value" id="progress-value"></div>
        </div>
        <p class="loading-text">
          <span id="loading-text">正在加载应用</span>
          <span class="dots"></span>
        </p>
      </div>
      <p class="version-info" id="version-info">版本 1.0.0</p>
      <p class="debug-info" id="debug-info">初始化中...</p>
    </div>
  </div>

  <script>
    // 进度条和消息
    const progressValue = document.getElementById('progress-value');
    const loadingText = document.getElementById('loading-text');
    const versionInfo = document.getElementById('version-info');
    const debugInfo = document.getElementById('debug-info');
    
    // 消息列表
    const messages = [
      '正在加载应用',
      '正在初始化',
      '正在加载资源',
      '正在准备工作区',
      '即将完成'
    ];
    
    // 自动进度
    let progress = 0;
    const startTime = Date.now();
    const duration = 3000;
    
    function updateProgress() {
      const now = Date.now();
      const elapsed = now - startTime;
      progress = Math.min(elapsed / duration * 100, 99);
      
      progressValue.style.width = `${progress}%`;
      
      if (progress < 99) {
        requestAnimationFrame(updateProgress);
      }
    }
    
    // 更新消息
    let messageIndex = 0;
    const messageInterval = setInterval(() => {
      messageIndex = (messageIndex + 1) % messages.length;
      loadingText.textContent = messages[messageIndex];
      
      if (progress >= 99) {
        clearInterval(messageInterval);
      }
    }, 1500);
    
    // 获取版本
    window.addEventListener('DOMContentLoaded', () => {
      console.log('启动界面已加载');
      
      // 显示调试信息
      debugInfo.textContent = `Electron: ${window.electron ? '可用' : '不可用'}`;
      if (window.electron) {
        debugInfo.textContent += `, IPC: ${window.electron.ipcRenderer ? '可用' : '不可用'}`;
      }
      
      // 通知主进程启动界面已加载
      if (window.electron?.ipcRenderer) {
        console.log('IPC 可用，发送 splash-ready 事件');
        debugInfo.textContent += ', 已发送 splash-ready 事件';
        window.electron.ipcRenderer.send('splash-ready');
        
        // 获取版本信息
        window.electron.ipcRenderer.invoke('get-app-version').then((version) => {
          console.log('获取版本成功:', version);
          versionInfo.textContent = `版本 ${version}`;
          debugInfo.textContent += `, 版本: ${version}`;
        }).catch(err => {
          console.error('获取版本失败:', err);
          debugInfo.textContent += `, 版本获取失败: ${err.message}`;
        });
        
        // 监听应用就绪事件
        window.electron.ipcRenderer.on('app-ready', () => {
          console.log('收到 app-ready 事件');
          debugInfo.textContent += ', 收到 app-ready 事件';
          progressValue.style.width = '100%';
          loadingText.textContent = '准备就绪';
          
          // 短暂延迟后通知主进程启动完成
          setTimeout(() => {
            console.log('发送 splash-complete 事件');
            debugInfo.textContent += ', 已发送 splash-complete 事件';
            window.electron?.ipcRenderer.send('splash-complete');
          }, 500);
        });
      } else {
        console.error('electron.ipcRenderer 不可用');
        debugInfo.textContent += ', IPC 不可用';
      }
      
      // 开始自动进度
      updateProgress();
    });
  </script>
</body>
</html> 